﻿using System;

public class NetHandler_Compensate : NetMessageHandler
{
    public const string Key = "Compensate";

    public static NetHandler_Compensate NewHandler()
    {
        return new NetHandler_Compensate();
    }

    protected override ISerialize NewData() => new CompensateDiamondData();

    public override void Execute(Remote client, ISerialize _data)
    {
        CompensateDiamondData data = _data as CompensateDiamondData;

        ResponseData response = new ResponseData();
        response.code = 0;

        data.date = GetCurDateInt();

        Game.instance.data.compensateData = data;

        GameDebug.Log($"Master  请求發放維護獎勵：{data.diamond}  date:{data.date}");

        byte[] senddata = response.Write();

        this.SendResponse(client, Key, this.m_MessageReceived.seq, senddata);
    }

    public static int GetCurDateInt()
    {
        return DateTime.Now.Year * 10000 + DateTime.Now.Month * 100 + DateTime.Now.Day;
    }

    public static DateTime GetDateTimeWithDateInt(int date)
    {
        DateTime dateTime = new DateTime(date / 10000, (date / 100) % 100, date % 100);

        GameDebug.Log($"dateTime:{dateTime}   dateInt:{date}");
        return dateTime;
    }
}